﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Sail
{
    /// <summary>
    /// 运行上下文访问接口
    /// </summary>
    public interface IWorkContextAccessor
    {
        /// <summary>
        /// 获取运行上下文对象
        /// </summary>
        /// <param name="httpContext">httpContext对象</param>
        /// <returns>运行上下文对象</returns>
        WorkContext GetContext(HttpContextBase httpContext);

        /// <summary>
        /// 获取运行上下文作用域对象
        /// </summary>
        /// <param name="httpContext">httpContext对象</param>
        /// <returns>运行上下文作用域对象</returns>
        IWorkContextScope CreateWorkContextScope(HttpContextBase httpContext);

        /// <summary>
        /// 获取运行上下文对象
        /// </summary>
        /// <returns>运行上下文对象</returns>
        WorkContext GetContext();

        /// <summary>
        /// 获取运行上下文作用域对象
        /// </summary>
        /// <returns>运行上下文作用域对象</returns>
        IWorkContextScope CreateWorkContextScope();
    }

    /// <summary>
    /// 运行上下文状态访问接口
    /// </summary>
    public interface IWorkContextStateProvider : IDependency
    {
        /// <summary>
        /// 获取上下文委托对象
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns>委托对象</returns>
        Func<WorkContext, T> Get<T>(string name);
    }

    /// <summary>
    /// 运行上下文作用域接口
    /// </summary>
    public interface IWorkContextScope : IDisposable
    {
        /// <summary>
        /// 运行上下文对象
        /// </summary>
        WorkContext WorkContext { get; }

        /// <summary>
        /// 解析
        /// </summary>
        /// <returns>服务对象</returns>
        TService Resolve<TService>();

        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="service">服务对象</param>
        /// <returns>true or false</returns>
        bool TryResolve<TService>(out TService service);    
    }
}
